home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / canacces < prev    next >
Text File  |  1996-04-09  |  2KB  |  60 lines

  1. /*----------------------------------------------------------------------
  2.        Check if we can access a file in a given way
  3.  
  4.    Args: file      -- The file to check
  5.          mode      -- The mode ala the access() system call, see ACCESS_EXISTS
  6.                       and friends in pine.h.
  7.  
  8.  Result: returns 0 if the user can access the file according to the mode,
  9.          -1 if he can't (and errno is set).
  10.  ----*/
  11. int
  12. can_access(file, mode)
  13.     char *file;
  14.     int   mode;
  15. {
  16.     return(access(file, mode));
  17. }
  18.  
  19.  
  20. /*----------------------------------------------------------------------
  21.        Check if we can access a file in a given way in the given path
  22.  
  23.    Args: path     -- The path to look for "file" in
  24.      file      -- The file to check
  25.          mode      -- The mode ala the access() system call, see ACCESS_EXISTS
  26.                       and friends in pine.h.
  27.  
  28.  Result: returns 0 if the user can access the file according to the mode,
  29.          -1 if he can't (and errno is set).
  30.  ----*/
  31. can_access_in_path(path, file, mode)
  32.     char *path, *file;
  33.     int   mode;
  34. {
  35.     char tmp[MAXPATH], *path_copy, *p, *t;
  36.     int  rv = -1;
  37.  
  38.     if(!path || !*path || *file == '/'){
  39.     rv = access(file, mode);
  40.     }
  41.     else if(*file == '~'){
  42.     strcpy(tmp, file);
  43.     rv = fnexpand(tmp, sizeof(tmp)) ? access(tmp, mode) : -1;
  44.     }
  45.     else{
  46.     for(p = path_copy = cpystr(path); p && *p; p = t){
  47.         if(t = strindex(p, ':'))
  48.           *t++ = '\0';
  49.  
  50.         sprintf(tmp, "%s/%s", p, file);
  51.         if((rv = access(tmp, mode)) == 0)
  52.           break;
  53.     }
  54.  
  55.     fs_give((void **)&path_copy);
  56.     }
  57.  
  58.     return(rv);
  59. }
  60.